package com.lmb.todo.dao;

import com.lmb.todo.pojo.Folder;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author lmb
 */
@Mapper
public interface FolderDao {

    /**
     * 根据 userId 获取全部的文件夹
     * @param userId Integer
     * @return List<Folder>
     */
    @Select("select id, userId, fname, descr, createTime, updateTime " +
            "from t_folder " +
            "where userId=${userId}")
    List<Folder> getAllByUserId(Integer userId);


    /**
     * 新增文件夹
     * @param folder Folder
     * @return Integer
     */
    @Insert("insert into t_folder(userId, fname, descr, createTime, updateTime) " +
            "values(#{userId}, #{fname}, #{descr}, #{createTime}, null)")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    Integer add(Folder folder);

     /**
     * 根据t_folder的id批量删除文件夹
     * @param ids Integerh
     * @return Integer
     * */
    @Delete("<script>" +
            "delete from t_folder " +
            "where id in (" +
            "<foreach collection='ids' item='id' separator=','>" +
            "#{id}" +
            "</foreach>" + ")" +
            "</script>")
    Integer deleteAll(List<Integer> ids);

    /**
     * 指定updateId更改t_group的folderId
     * @param folderId Integer
     * @param updateId Integer
     * @return Integer
     */
    @Update("update t_group set folderId=#{updateId} where folderId=#{folderId}")
    Integer updateGroupByFolderId(Integer folderId, Integer updateId);
}
